import 'package:flutter_simple_watch/base/base_repository.dart';
import 'package:flutter_simple_watch/base/base_result.dart';
import 'package:flutter_simple_watch/news/api/we_chat_api.dart';
import 'package:flutter_simple_watch/news/api/we_chat_api_service.dart';

///@author aidenquan
/// Created by junlintianxia on 1/15/21.

class WeChatNewsModel extends BaseRepository {
  WeChatNewsModel() {
    setDio(WeChatApiService.instance.getDio());
  }

  int lastMaxPageNewsRecord = -1;

  setLastMaxPageNewsRecord(int lastPage) {
    lastMaxPageNewsRecord = lastPage;
  }

  int getLastMaxPageNewsRecord() {
    if (lastMaxPageNewsRecord < 0) {
      return 0;
    } else {
      return lastMaxPageNewsRecord;
    }
  }

  /// 获取微信新闻
  Future<dynamic> getWeChatNews(String channel, int limitNum, bool isDown) async {
    Map<String, dynamic> queryParams = {};
    queryParams['num'] = limitNum;
    queryParams['page'] = getLastMaxPageNewsRecord();
    BaseResult result =  await get(WeChatApi.getWeChatNews(), params: queryParams);
    if (result.data != null) {
      setLastMaxPageNewsRecord(getLastMaxPageNewsRecord() + 1);
    }
    return result;
  }
}
